package com.lmuse.xmr.foodspotting.ui.classify;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.lmuse.xmr.foodspotting.R;

public class ExpandableAdapter extends BaseExpandableListAdapter {

    private String[] groupStrings = {
            "时间", "制作方法", "地方特色", "小吃"
    };

    private String[][] childStrings = {
            {"早餐","午餐","晚餐"},
            {"家常菜","蒸菜","炖菜","炒菜","素食","瘦身餐","汤类","主食"},
            {"川菜","湘菜","东北菜","清真菜","日本料理","韩国料理"},
            {"甜点","西点"}
    };

    @Override
    public int getGroupCount() {
            return groupStrings.length;
    }

    @Override
    public int getChildrenCount(int i) {
        return childStrings[i].length;
    }

    @Override
    public Object getGroup(int i) {
        return groupStrings[i];
    }

    @Override
    public Object getChild(int i, int i1) {
        return childStrings[i][i1];
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return true ;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        GroupViewHolder groupViewHolder;
        if (view == null) {
            view = LayoutInflater.from(viewGroup.getContext())
                    .inflate(R.layout.expandable_list_group_item, viewGroup, false);
            groupViewHolder = new GroupViewHolder();
            groupViewHolder.tvTitle = (TextView) view.findViewById(R.id.expand_tv_group);
            view.setTag(groupViewHolder);
        } else {
            groupViewHolder = (GroupViewHolder) view.getTag();
        }
        groupViewHolder.tvTitle.setText(groupStrings[i]);
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        ChildViewHolder childViewHolder;
        if (view == null) {
            view = LayoutInflater.from(viewGroup.getContext())
                    .inflate(R.layout.expandable_list_item, viewGroup, false);
            childViewHolder = new ChildViewHolder();
            childViewHolder.tvTitle = (TextView) view.findViewById(R.id.expand_tv_item);
            view.setTag(childViewHolder);
        } else {
            childViewHolder = (ChildViewHolder) view.getTag();
        }
        childViewHolder.tvTitle.setText(childStrings[i][i1]);
        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }

    static class GroupViewHolder {
        TextView tvTitle;
    }
    static class ChildViewHolder {
        TextView tvTitle;
    }
}
